$(function(){
    $('.smslogin a[action=submit]').on('click',leftlogin);
    $('.smslogin').find('input').on('keydown',function(){
        if (event.keyCode == "13") {
             $('.smslogin a[action=submit]').click();
         }
    });
    $('.emailform a[action=submit]').on('click',rightlogin);
    $('.emailform').find('input').on('keydown',function(){
        if (event.keyCode == "13") {
             $('.emailform a[action=submit]').click();
         }
    });
    
    $("#11_timer1033").click(function(){
    	smsSendpwd();
  	  });
    $("#6_timer2078").click(function(){
    	sendpwdEmail();
  	  });
	 
});
/**
 * 发送短信验证码
 */
var smsSendpwd=function(){
	 var obj=$("#11_timer1033");
	 var phone = $(obj.parents('form').find('[name=mobile]')[0]).val();
	 if(phone==null || phone.length==0) {
		 showModal('请输入正确格式的手机号码');
		 $(obj.parents('form').find('[name=mobile]')[0]).addClass("input-error");
		 return false;
	 } else if(phone.length==11) {
		 $(obj.parents('form').find('[name=mobile]')[0]).removeClass("input-error");
	 } 
	 var smsurl=$("#loginFormId").attr("action");
	 var len=smsurl.lastIndexOf("/");
	 smsurl=smsurl.substring(0,len);
	 smsurl=smsurl+"/sendLoginSms?mobile="+phone;
	 $.ajax({
		 type:'get',
		 url:smsurl,
		 success:function(data){
			 if(data.code=='error') {
				 showModal(data.info);
			 } else {
				 fun_timedown("11_timer1033",60);
				 showModal(data.info);
				 $("#11_timer1033").unbind("click");
			 }
		 }
	 });
};

/**
 * 发送email
 */
var sendpwdEmail=function(){
	 var obj=$("#6_timer2078");
	 var email = $(obj.parents('form').find('[name=email]')[0]).val();
	 if(email==null || email.length==0) {
		 showModal('请输入E-mail');
		 $(obj.parents('form').find('[name=email]')[0]).addClass("input-error");
		 return false;
	 } else if(email.length==11) {
		 $(obj.parents('form').find('[name=email]')[0]).removeClass("input-error");
	 } 
	 var smsurl=$("#loginFormId").attr("action");
	 var len=smsurl.lastIndexOf("/");
	 smsurl=smsurl.substring(0,len);
	 smsurl=smsurl+"/sendfindPaswdEmail?email="+email;
	 $.ajax({
		 type:'get',
		 url:smsurl,
		 success:function(data){
			 if(data.code=='error') {
				 showModal(data.info);
			 } else {
				 fun_timedown("6_timer2078",60);
				 showModal(data.info);
				 $("#6_timer2078").unbind("click");
			 }
		 }
	 });
};
function leftlogin(){
    $('.smslogin').Qsubmit(null,function(msg){
        showModal(msg);
        $('.smslogin').find('img[name=img]').click();
    });
}
function rightlogin(){
    $('.emailform').Qsubmit(null,function(msg){
        showModal(msg);
        $('.emailform').find('img[name=img]').click();
    });
}
  /**
   * 倒计时
   */
  function fun_timedown(str,time) {
  	$("#"+str).text(time+"秒");
      time = time-1;
      if(time>=0){
          setTimeout("fun_timedown('"+str+"','"+time+"')",1000);
      }else{
      		$("#"+str).bind("click", function(){smsSend(str);});
      		$("#"+str).text("发送验证码");
      }
  }